package com.cictec.middleware.tde.rm.protocol.rm.decode;

import java.nio.ByteBuffer;

import org.apache.mina.core.session.IoSession;

import com.cictec.middleware.commons.utils.BinaryUtils;
import com.cictec.middleware.tde.exception.MessageDecoderException;
import com.cictec.middleware.tde.rm.protocol.AbstractMessageDecoder;
import com.cictec.middleware.tde.rm.protocol.TerminalMessage;
import com.cictec.middleware.tde.rm.protocol.TerminalMessage.Header;
import com.cictec.middleware.tde.rm.protocol.annotion.TerminalMessageDecoder;
import com.cictec.middleware.tde.rm.protocol.rm.message.Rm0x06TerminalMessage;
import com.cictec.middleware.tde.rm.protocol.rm.utils.RmBinaryUtils;

/**
 * 0x06 指令应答
 * 
 * @author lhl
 *
 */
@TerminalMessageDecoder(0x06)
public class Rm0x06Decoder extends AbstractMessageDecoder {

	@Override
	public TerminalMessage decode(Header header, ByteBuffer in, IoSession session) throws MessageDecoderException {

		Rm0x06TerminalMessage tgp = new Rm0x06TerminalMessage(header);
		tgp.setResponseTime(RmBinaryUtils.dwordToDateRM(in));
		tgp.setResponseMessageId(BinaryUtils.unsignedByteToInt(in));
		tgp.setResponseSequence(BinaryUtils.unsignedByteToInt(in));
		tgp.setResponseType(BinaryUtils.unsignedByteToInt(in));
		tgp.setReserved(BinaryUtils.wordToInt(in));
		return tgp;
	}

}
